#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct a{
	char id[19];
	int zuowei;
	int kaoshi;
	}ids;
	
int main(){
	int lens;
	cin>>lens;
	ids data[1001];
	for(int i=0;i<lens;i++){
		cin>>data[i].id>>data[i].zuowei>>data[i].kaoshi;
	}
	int count,temp;
	cin>>count;
	while(count--){
		cin>>temp;
		for(int i=0;i<lens;i++){
			if(data[i].zuowei==temp){
				cout<<data[i].ids<<' '<<data[i].kaoshi;
				break;
			}
		}
	}
}